{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "38670784",
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests # 调用 requests 模块\n",
    "\n",
    "geo_url = 'https://restapi.amap.com/v3/geocode/geo?parameters' # 请求的调用url\n",
    "\n",
    "# 请求方式：GET\n",
    "# 请求参数\n",
    "payload = {\n",
    "    'key':'aaa5520182ed361dc22933ce4acf40e6',\n",
    "    'address':'广东省广州市从化区广州南方学院'\n",
    "}\n",
    "\n",
    "# 发起请求\n",
    "r = requests.get(url = geo_url, params = payload)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "769ccd7c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'113.678280,23.628439'"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.json()['geocodes'][0]['location']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "d27faa08",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'113.678280,23.628439'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "NFU_location = r.json()['geocodes'][0]['location']\n",
    "NFU_location"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "90457a78",
   "metadata": {},
   "outputs": [],
   "source": [
    "para_url = 'https://restapi.amap.com/v5/place/around?parameters' # 请求的调用url\n",
    "\n",
    "payload = {\n",
    "    'key':'aaa5520182ed361dc22933ce4acf40e6',\n",
    "    'location':NFU_location ,\n",
    "    'types':'050100|050300|050201'\n",
    "}\n",
    "\n",
    "r = requests.get(url = para_url, params = payload)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "14d9cbc3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'status': '1',\n",
       " 'info': 'OK',\n",
       " 'infocode': '10000',\n",
       " 'pois': [{'name': '我家卖米粉(中大店)',\n",
       "   'id': 'B0HRO7MT5G',\n",
       "   'location': '113.678455,23.628393',\n",
       "   'type': '餐饮服务;中餐厅;中餐厅',\n",
       "   'typecode': '050100',\n",
       "   'pname': '广东省',\n",
       "   'cityname': '广州市',\n",
       "   'adname': '从化区',\n",
       "   'address': '温泉镇中山大学南方学院后门润泰超市首层01-02号商铺',\n",
       "   'pcode': '440000',\n",
       "   'citycode': '020',\n",
       "   'adcode': '440117'},\n",
       "  {'name': '喜洋洋烧烤城',\n",
       "   'id': 'B0FFKT56Q8',\n",
       "   'location': '113.678474,23.628422',\n",
       "   'type': '餐饮服务;中餐厅;中餐厅',\n",
       "   'typecode': '050100',\n",
       "   'pname': '广东省',\n",
       "   'cityname': '广州市',\n",
       "   'adname': '从化区',\n",
       "   'address': '博学路6号(广州南方学院南门口旁)',\n",
       "   'pcode': '440000',\n",
       "   'citycode': '020',\n",
       "   'adcode': '440117'},\n",
       "  {'name': 'PROJECT.B美式汉堡(中大店)',\n",
       "   'id': 'B0HROCM4JK',\n",
       "   'location': '113.678983,23.627778',\n",
       "   'type': '餐饮服务;快餐厅;快餐厅',\n",
       "   'typecode': '050300',\n",
       "   'pname': '广东省',\n",
       "   'cityname': '广州市',\n",
       "   'adname': '从化区',\n",
       "   'address': '温泉镇南方公寓',\n",
       "   'pcode': '440000',\n",
       "   'citycode': '020',\n",
       "   'adcode': '440117'},\n",
       "  {'name': '港式住家饭(中大店)',\n",
       "   'id': 'B0H1M90UGD',\n",
       "   'location': '113.679504,23.628108',\n",
       "   'type': '餐饮服务;中餐厅;中餐厅',\n",
       "   'typecode': '050100',\n",
       "   'pname': '广东省',\n",
       "   'cityname': '广州市',\n",
       "   'adname': '从化区',\n",
       "   'address': '温泉镇中山大学南方学院',\n",
       "   'pcode': '440000',\n",
       "   'citycode': '020',\n",
       "   'adcode': '440117'},\n",
       "  {'name': '找餐时间(轻食店)',\n",
       "   'id': 'B0H31YY48Q',\n",
       "   'location': '113.679695,23.628204',\n",
       "   'type': '餐饮服务;中餐厅;中餐厅',\n",
       "   'typecode': '050100',\n",
       "   'pname': '广东省',\n",
       "   'cityname': '广州市',\n",
       "   'adname': '从化区',\n",
       "   'address': '温泉镇中大南方',\n",
       "   'pcode': '440000',\n",
       "   'citycode': '020',\n",
       "   'adcode': '440117'},\n",
       "  {'name': '1号粥店',\n",
       "   'id': 'B0HROCMB8D',\n",
       "   'location': '113.679738,23.628307',\n",
       "   'type': '餐饮服务;中餐厅;中餐厅',\n",
       "   'typecode': '050100',\n",
       "   'pname': '广东省',\n",
       "   'cityname': '广州市',\n",
       "   'adname': '从化区',\n",
       "   'address': '温泉镇中山大学南方学院',\n",
       "   'pcode': '440000',\n",
       "   'citycode': '020',\n",
       "   'adcode': '440117'},\n",
       "  {'name': '巴老冒豆花冒菜(中大店)',\n",
       "   'id': 'B0HROCISXU',\n",
       "   'location': '113.679739,23.628221',\n",
       "   'type': '餐饮服务;中餐厅;中餐厅',\n",
       "   'typecode': '050100',\n",
       "   'pname': '广东省',\n",
       "   'cityname': '广州市',\n",
       "   'adname': '从化区',\n",
       "   'address': '温泉镇中大南方',\n",
       "   'pcode': '440000',\n",
       "   'citycode': '020',\n",
       "   'adcode': '440117'},\n",
       "  {'name': '牛哥烧烤',\n",
       "   'id': 'B0HROCM3MH',\n",
       "   'location': '113.679809,23.628326',\n",
       "   'type': '餐饮服务;中餐厅;特色/地方风味餐厅',\n",
       "   'typecode': '050118',\n",
       "   'pname': '广东省',\n",
       "   'cityname': '广州市',\n",
       "   'adname': '从化区',\n",
       "   'address': '温泉镇中山大学南方学院',\n",
       "   'pcode': '440000',\n",
       "   'citycode': '020',\n",
       "   'adcode': '440117'},\n",
       "  {'name': '十三幺熟食牛杂',\n",
       "   'id': 'B0G3ASF92M',\n",
       "   'location': '113.679565,23.627501',\n",
       "   'type': '餐饮服务;快餐厅;快餐厅',\n",
       "   'typecode': '050300',\n",
       "   'pname': '广东省',\n",
       "   'cityname': '广州市',\n",
       "   'adname': '从化区',\n",
       "   'address': '温泉镇广州南方学院后门润泰超市1层05号商铺',\n",
       "   'pcode': '440000',\n",
       "   'citycode': '020',\n",
       "   'adcode': '440117'},\n",
       "  {'name': '香辣螺蛳粉',\n",
       "   'id': 'B0FFKSF1FI',\n",
       "   'location': '113.676231,23.628565',\n",
       "   'type': '餐饮服务;快餐厅;快餐厅',\n",
       "   'typecode': '050300',\n",
       "   'pname': '广东省',\n",
       "   'cityname': '广州市',\n",
       "   'adname': '从化区',\n",
       "   'address': '广州南方学院西4123',\n",
       "   'pcode': '440000',\n",
       "   'citycode': '020',\n",
       "   'adcode': '440117'}],\n",
       " 'count': '10'}"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "33c7ae9f",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "1bee6ec3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "      <th>4</th>\n",
       "      <th>5</th>\n",
       "      <th>6</th>\n",
       "      <th>7</th>\n",
       "      <th>8</th>\n",
       "      <th>9</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>name</th>\n",
       "      <td>我家卖米粉(中大店)</td>\n",
       "      <td>喜洋洋烧烤城</td>\n",
       "      <td>PROJECT.B美式汉堡(中大店)</td>\n",
       "      <td>港式住家饭(中大店)</td>\n",
       "      <td>找餐时间(轻食店)</td>\n",
       "      <td>1号粥店</td>\n",
       "      <td>巴老冒豆花冒菜(中大店)</td>\n",
       "      <td>牛哥烧烤</td>\n",
       "      <td>十三幺熟食牛杂</td>\n",
       "      <td>香辣螺蛳粉</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>id</th>\n",
       "      <td>B0HRO7MT5G</td>\n",
       "      <td>B0FFKT56Q8</td>\n",
       "      <td>B0HROCM4JK</td>\n",
       "      <td>B0H1M90UGD</td>\n",
       "      <td>B0H31YY48Q</td>\n",
       "      <td>B0HROCMB8D</td>\n",
       "      <td>B0HROCISXU</td>\n",
       "      <td>B0HROCM3MH</td>\n",
       "      <td>B0G3ASF92M</td>\n",
       "      <td>B0FFKSF1FI</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>location</th>\n",
       "      <td>113.678455,23.628393</td>\n",
       "      <td>113.678474,23.628422</td>\n",
       "      <td>113.678983,23.627778</td>\n",
       "      <td>113.679504,23.628108</td>\n",
       "      <td>113.679695,23.628204</td>\n",
       "      <td>113.679738,23.628307</td>\n",
       "      <td>113.679739,23.628221</td>\n",
       "      <td>113.679809,23.628326</td>\n",
       "      <td>113.679565,23.627501</td>\n",
       "      <td>113.676231,23.628565</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>type</th>\n",
       "      <td>餐饮服务;中餐厅;中餐厅</td>\n",
       "      <td>餐饮服务;中餐厅;中餐厅</td>\n",
       "      <td>餐饮服务;快餐厅;快餐厅</td>\n",
       "      <td>餐饮服务;中餐厅;中餐厅</td>\n",
       "      <td>餐饮服务;中餐厅;中餐厅</td>\n",
       "      <td>餐饮服务;中餐厅;中餐厅</td>\n",
       "      <td>餐饮服务;中餐厅;中餐厅</td>\n",
       "      <td>餐饮服务;中餐厅;特色/地方风味餐厅</td>\n",
       "      <td>餐饮服务;快餐厅;快餐厅</td>\n",
       "      <td>餐饮服务;快餐厅;快餐厅</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>typecode</th>\n",
       "      <td>050100</td>\n",
       "      <td>050100</td>\n",
       "      <td>050300</td>\n",
       "      <td>050100</td>\n",
       "      <td>050100</td>\n",
       "      <td>050100</td>\n",
       "      <td>050100</td>\n",
       "      <td>050118</td>\n",
       "      <td>050300</td>\n",
       "      <td>050300</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>pname</th>\n",
       "      <td>广东省</td>\n",
       "      <td>广东省</td>\n",
       "      <td>广东省</td>\n",
       "      <td>广东省</td>\n",
       "      <td>广东省</td>\n",
       "      <td>广东省</td>\n",
       "      <td>广东省</td>\n",
       "      <td>广东省</td>\n",
       "      <td>广东省</td>\n",
       "      <td>广东省</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>cityname</th>\n",
       "      <td>广州市</td>\n",
       "      <td>广州市</td>\n",
       "      <td>广州市</td>\n",
       "      <td>广州市</td>\n",
       "      <td>广州市</td>\n",
       "      <td>广州市</td>\n",
       "      <td>广州市</td>\n",
       "      <td>广州市</td>\n",
       "      <td>广州市</td>\n",
       "      <td>广州市</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>adname</th>\n",
       "      <td>从化区</td>\n",
       "      <td>从化区</td>\n",
       "      <td>从化区</td>\n",
       "      <td>从化区</td>\n",
       "      <td>从化区</td>\n",
       "      <td>从化区</td>\n",
       "      <td>从化区</td>\n",
       "      <td>从化区</td>\n",
       "      <td>从化区</td>\n",
       "      <td>从化区</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>address</th>\n",
       "      <td>温泉镇中山大学南方学院后门润泰超市首层01-02号商铺</td>\n",
       "      <td>博学路6号(广州南方学院南门口旁)</td>\n",
       "      <td>温泉镇南方公寓</td>\n",
       "      <td>温泉镇中山大学南方学院</td>\n",
       "      <td>温泉镇中大南方</td>\n",
       "      <td>温泉镇中山大学南方学院</td>\n",
       "      <td>温泉镇中大南方</td>\n",
       "      <td>温泉镇中山大学南方学院</td>\n",
       "      <td>温泉镇广州南方学院后门润泰超市1层05号商铺</td>\n",
       "      <td>广州南方学院西4123</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>pcode</th>\n",
       "      <td>440000</td>\n",
       "      <td>440000</td>\n",
       "      <td>440000</td>\n",
       "      <td>440000</td>\n",
       "      <td>440000</td>\n",
       "      <td>440000</td>\n",
       "      <td>440000</td>\n",
       "      <td>440000</td>\n",
       "      <td>440000</td>\n",
       "      <td>440000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>citycode</th>\n",
       "      <td>020</td>\n",
       "      <td>020</td>\n",
       "      <td>020</td>\n",
       "      <td>020</td>\n",
       "      <td>020</td>\n",
       "      <td>020</td>\n",
       "      <td>020</td>\n",
       "      <td>020</td>\n",
       "      <td>020</td>\n",
       "      <td>020</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>adcode</th>\n",
       "      <td>440117</td>\n",
       "      <td>440117</td>\n",
       "      <td>440117</td>\n",
       "      <td>440117</td>\n",
       "      <td>440117</td>\n",
       "      <td>440117</td>\n",
       "      <td>440117</td>\n",
       "      <td>440117</td>\n",
       "      <td>440117</td>\n",
       "      <td>440117</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                    0                     1  \\\n",
       "name                       我家卖米粉(中大店)                喜洋洋烧烤城   \n",
       "id                         B0HRO7MT5G            B0FFKT56Q8   \n",
       "location         113.678455,23.628393  113.678474,23.628422   \n",
       "type                     餐饮服务;中餐厅;中餐厅          餐饮服务;中餐厅;中餐厅   \n",
       "typecode                       050100                050100   \n",
       "pname                             广东省                   广东省   \n",
       "cityname                          广州市                   广州市   \n",
       "adname                            从化区                   从化区   \n",
       "address   温泉镇中山大学南方学院后门润泰超市首层01-02号商铺     博学路6号(广州南方学院南门口旁)   \n",
       "pcode                          440000                440000   \n",
       "citycode                          020                   020   \n",
       "adcode                         440117                440117   \n",
       "\n",
       "                             2                     3                     4  \\\n",
       "name        PROJECT.B美式汉堡(中大店)            港式住家饭(中大店)             找餐时间(轻食店)   \n",
       "id                  B0HROCM4JK            B0H1M90UGD            B0H31YY48Q   \n",
       "location  113.678983,23.627778  113.679504,23.628108  113.679695,23.628204   \n",
       "type              餐饮服务;快餐厅;快餐厅          餐饮服务;中餐厅;中餐厅          餐饮服务;中餐厅;中餐厅   \n",
       "typecode                050300                050100                050100   \n",
       "pname                      广东省                   广东省                   广东省   \n",
       "cityname                   广州市                   广州市                   广州市   \n",
       "adname                     从化区                   从化区                   从化区   \n",
       "address                温泉镇南方公寓           温泉镇中山大学南方学院               温泉镇中大南方   \n",
       "pcode                   440000                440000                440000   \n",
       "citycode                   020                   020                   020   \n",
       "adcode                  440117                440117                440117   \n",
       "\n",
       "                             5                     6                     7  \\\n",
       "name                      1号粥店          巴老冒豆花冒菜(中大店)                  牛哥烧烤   \n",
       "id                  B0HROCMB8D            B0HROCISXU            B0HROCM3MH   \n",
       "location  113.679738,23.628307  113.679739,23.628221  113.679809,23.628326   \n",
       "type              餐饮服务;中餐厅;中餐厅          餐饮服务;中餐厅;中餐厅    餐饮服务;中餐厅;特色/地方风味餐厅   \n",
       "typecode                050100                050100                050118   \n",
       "pname                      广东省                   广东省                   广东省   \n",
       "cityname                   广州市                   广州市                   广州市   \n",
       "adname                     从化区                   从化区                   从化区   \n",
       "address            温泉镇中山大学南方学院               温泉镇中大南方           温泉镇中山大学南方学院   \n",
       "pcode                   440000                440000                440000   \n",
       "citycode                   020                   020                   020   \n",
       "adcode                  440117                440117                440117   \n",
       "\n",
       "                               8                     9  \n",
       "name                     十三幺熟食牛杂                 香辣螺蛳粉  \n",
       "id                    B0G3ASF92M            B0FFKSF1FI  \n",
       "location    113.679565,23.627501  113.676231,23.628565  \n",
       "type                餐饮服务;快餐厅;快餐厅          餐饮服务;快餐厅;快餐厅  \n",
       "typecode                  050300                050300  \n",
       "pname                        广东省                   广东省  \n",
       "cityname                     广州市                   广州市  \n",
       "adname                       从化区                   从化区  \n",
       "address   温泉镇广州南方学院后门润泰超市1层05号商铺           广州南方学院西4123  \n",
       "pcode                     440000                440000  \n",
       "citycode                     020                   020  \n",
       "adcode                    440117                440117  "
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.json_normalize(r.json()['pois']).T"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "059d218c",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4fe9dc2a",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b81ce18b",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
